//
//  MTNewsListCell.m
//  MobTimes
//
//  Created by 江山 王 on 5/12/12.
//  Copyright (c) 2012 Finalist. All rights reserved.
//

#define IMAGE_VIEW_TAG                          (4)
#define DETAIL_LABEL_TAG                        (6)
#define TITLE_LABEL_TAG                         (7)

#import "MTStartupsCell.h"
#import <QuartzCore/QuartzCore.h>
#import "MTLabel.h"

@implementation MTStartupsCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)drawRect:(CGRect)rect {
	[super drawRect:rect];
	
	//用2像素的白色描边遮挡1像素的灰色描边,达到画1像素灰线下面2像素白线的目的
    CGContextRef c = UIGraphicsGetCurrentContext();
    
	
	//add 1px gray stroke
	CGFloat gray[4] = {40/255.0f, 40/255.0f, 40/255.0f, 1.0f};	
	CGContextSetLineWidth(c, 0.5f);
    CGContextSetStrokeColor(c, gray);
    CGContextBeginPath(c);
    CGContextMoveToPoint(c, 0.0f, 80.0f - 1.0f);
    CGContextAddLineToPoint(c, 320, 80.0f - 1.0f);
    CGContextStrokePath(c);
	
	//add 2px white stroke
	CGFloat white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
	CGContextSetLineWidth(c, 0.5f);
    CGContextSetStrokeColor(c, white);
    CGContextBeginPath(c);
    CGContextMoveToPoint(c, 0.0f, 80.0f - 0.5f);
    CGContextAddLineToPoint(c, 320, 80.0f - 0.5f);
    CGContextStrokePath(c);
	
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    //图片
    UIImageView *_imageView = (UIImageView *)[self.contentView viewWithTag:IMAGE_VIEW_TAG];
    _imageView.layer.borderWidth = 0.5;
    _imageView.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2].CGColor;
    _imageView.layer.shadowOpacity = 0.8;
    _imageView.layer.shadowOffset = CGSizeMake(2, 2);
    _imageView.layer.shadowColor = [UIColor grayColor].CGColor;
    
    //标题
    CGFloat kTextLabelTextLineHeight = 16.0f;
    CGFloat kTextLabelTextLines = 1;
    MTLabel *_textLabel = (MTLabel *)[self.contentView viewWithTag:TITLE_LABEL_TAG];
    _textLabel.font = [UIFont systemFontOfSize:14];
    [_textLabel setTextAlignment:MTLabelTextAlignmentLeft];
    _textLabel.fontColor = [UIColor blackColor];
    _textLabel.numberOfLines = kTextLabelTextLines;
    _textLabel.limitToNumberOfLines = YES;
    _textLabel.lineHeight = kTextLabelTextLineHeight;
    _textLabel.backgroundColor = [UIColor clearColor];
    _textLabel.frame = CGRectMake(78, 7, 200.0f, kTextLabelTextLineHeight);
    
    //摘要
    CGFloat kDetailLabelTextLines = 2;
    CGFloat kDetailLabelTextLineHeight = 14;
    MTLabel *_detailTextLabel = (MTLabel *)[self.contentView viewWithTag:DETAIL_LABEL_TAG];
    [_detailTextLabel setTextAlignment:MTLabelTextAlignmentLeft];
    _detailTextLabel.backgroundColor = [UIColor clearColor];
    _detailTextLabel.font = [UIFont systemFontOfSize:11];
    _detailTextLabel.fontColor = [UIColor grayColor];
    _detailTextLabel.numberOfLines = kDetailLabelTextLines;
    _detailTextLabel.limitToNumberOfLines = YES;
    _detailTextLabel.lineHeight = kDetailLabelTextLineHeight;
    _detailTextLabel.frame = CGRectMake(78, 26, 230, kDetailLabelTextLineHeight*kDetailLabelTextLines);
    
    //作者
    UILabel *_authorLabel = (UILabel *)[self.contentView viewWithTag:AUTHOR_LABEL_TAG];
    if (_authorLabel) {
        _authorLabel.frame = CGRectMake(78, 57, 220, 20);
        _authorLabel.font = [UIFont systemFontOfSize:10];
        _authorLabel.backgroundColor = [UIColor clearColor];
        _authorLabel.textAlignment = UITextAlignmentLeft;
    }
    
}

@end
